package Teach;

import java.io.*;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.18.12.32
 */
//将java源文件内容读取，并写入.txt
public class Pj4 {
    public static void main(String[] args) {
        //读取文件
        File f=new File("my.java");
        File t=new File("my.txt");
        //t.delete();
        //f.delete();
        if(f.exists()){
            try(FileInputStream fis=new FileInputStream(f)){
            byte[] buf=new byte[1024];
            int len=0;
            while ((len=fis.read(buf))>0){
                System.out.println(new String(buf,"UTF-8"));

                FileOutputStream fos=new FileOutputStream(t,true);
               // fos.write("%s%n",buf);
                fos.write((buf));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        }
    }
}
